package com.yaj.myfactorysupport.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yaj.myfactorysupport.entity.VTmItem;
import com.yaj.myfactorysupport.mapper.VTmItemMapper;
import com.yaj.myfactorysupport.service.VTmItemService;
import com.yaj.myfactorysupport.util.ErrorCodeEnum;
import com.yaj.myfactorysupport.util.RespBean;
import com.yaj.myfactorysupport.vo.VTmItemVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wei
 * @since 2021-06-02
 */
@Service
public class VTmItemServiceImpl extends ServiceImpl<VTmItemMapper, VTmItem> implements VTmItemService {
    @Resource
    private VTmItemMapper vTmItemMapper;

    @Override
    public RespBean getCavitNumByItemId(String itemId) {
        VTmItem vTmItem = vTmItemMapper.selectOne(new QueryWrapper<VTmItem>().lambda().eq(VTmItem::getItemId, itemId).ne(VTmItem::getMmId,"PARTS"));

        if(ObjectUtil.isNull(vTmItem)){
            return RespBean.error(ErrorCodeEnum.没有找到对应的基板取数.getCode(),ErrorCodeEnum.没有找到对应的基板取数.getMsg());
        }
        VTmItemVo vTmItemVo = new VTmItemVo();
        BeanUtil.copyProperties(vTmItem,vTmItemVo);

        return RespBean.success(vTmItemVo);
    }
}
